package util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class AreaFileCleanup {
	public static void main(String[] args){
		File fIn = new File("c:\\Users\\Jamison\\Documents\\PopulationInfo\\MarylandArea.txt");
		File fOut = new File("c:\\Users\\Jamison\\Documents\\PopulationInfo\\MarylandArea2.txt");
		StringBuilder builder = new StringBuilder(200);
		try{
			BufferedReader reader = new BufferedReader(new FileReader(fIn));
			String line = null;
			while ((line = reader.readLine()) != null){
//				String test[] = line.split("( ++)");
				String test[] = line.split("( ++\t|\t ++| ++|\t)");
				
				//city
				for (int i = 0; i < test.length; i++){
					if (i <test.length - 10 || i > test.length - 7){
						builder.append(test[i]);
						builder.append(" ");
					}
				}
				
				//non city
//				for (int i = 0; i < test.length; i++){
//					if (i <test.length - 9 || i > test.length - 7){
//						builder.append(test[i]);
//						builder.append(" ");
//					}
//				}
				
				builder.append("\n");
//				builder.append(test[test.length - 7]);
//				builder.append(" ");
//				builder.append(test[test.length - 8]);
//				builder.append(" ");
//				builder.append(test[test.length - 9]);
//				builder.append(" ");
//				builder.append(test[test.length - 10]);
//				System.out.println(builder.toString());
			}
			reader.close();
			
			BufferedWriter writer = new BufferedWriter(new FileWriter(fOut));
			writer.write(builder.toString());
			writer.close();
		}
		catch (FileNotFoundException e){
			e.printStackTrace();
		} 
		catch (IOException e){
			e.printStackTrace();
		}
	}
}
